package taller2.controller.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JToggleButton;

import taller2.interfaces.HidableWindow;
import taller2.view.menus.UserImputMenu;

public class UserImputListener implements ActionListener{
	protected UserImputMenu menu;
	protected HidableWindow window;
	
	// constructor
	public UserImputListener(){
	}
	
	public void set(UserImputMenu menu, HidableWindow window){
		this.menu = menu;
		this.window = window;
	}

	@Override
	public void actionPerformed(ActionEvent event){
		JToggleButton button = (JToggleButton)event.getSource();
		menu.unselectButtons();
		
		if(menu.isAccept(button)){
			String response = menu.getResponse();
			String solution = menu.getSolution();

			JFrame frame = new JFrame();

			if(response.equalsIgnoreCase(solution)){
				JOptionPane.showMessageDialog(frame, "Good job!!!");
			}else{
				JOptionPane.showMessageDialog(frame, "the answer was incorrect, the expected answer was:\n"+solution);			
			}
		}
		
		if(menu.isCancel(button))
			window.setVisible(false);
	}
	
}
